#ifndef __MCS__ELEMENT__HPP
#define __MCS__ELEMENT__HPP

#include "Object.hpp"
#include "SourceLocation.hpp"

class Block;

/// Abstract class for program element
/**
Elements are grouped into blocks. Each element is a child of its block.
See the Block class for details about element-block relations.

@todo: Get rid of the concat() method via detailing grammar definition.
*/
class Element : public Object
{
public:
	Element(SourceLocation const & location)
		: Object()
		, parentBlock_()
		, location_(location)
	{}

	/// Returns location of the source file occupied by this element.
	SourceLocation const & location() const { return location_; }

	/// Returns pointer to parent block object.
	Block * parentBlock() const { return parentBlock_; }

	/// Performs post-constructor initialization.
	virtual void init(Block * parentBlock) { parentBlock_ = parentBlock; }

	/// Executes scipt element that is represented by this block.
	virtual void execute() const = 0;

	/// Concatenates this element with \p other into block.
	/** Note: Implemented in Block.cpp */
	virtual ptr<Element> concat(ptr<Element> other);
private:
	Block * parentBlock_;
	SourceLocation location_;
};


#endif //__MCS__ELEMENT__HPP
